import {
	RECORD_USERINFO,
	GET_USERINFO,
	RECORD_ACCOUNT,
	GET_ACCOUNT,
	OUT_LOGIN,
	SAVE_AVANDER,
} from './mutation-types.js'

import { setStore, getStore } from '../config/mUtils'

import { localapi, proapi } from 'src/config/env'

export default {
	// 记录用户信息
	[RECORD_USERINFO](state, info) {
		// window.location.reload(); 	// 页面强制刷新
		setStore('userInfo', info);
		state.userInfo = info;
	},
	//获取用户信息存入vuex
	[GET_USERINFO](state) {
		if (!state.userInfo) {
			state.userInfo = JSON.parse(getStore('userInfo'))
		}
		return state.userInfo;
	},
	// 记录账户信息
	[RECORD_ACCOUNT](state, data) {
		setStore('accountInfo', data);
		state.accountInfo = data;
	},
	//获取账户信息存入vuex
	[GET_ACCOUNT](state) {
		if (!state.accountInfo) {
			state.accountInfo = JSON.parse(getStore('accountInfo'))
		}
	},
	//退出登录
	[OUT_LOGIN](state) {
		setStore('userInfo', {});
		state.userInfo = {};
		// state.login = false;
	},
	//保存图片
	[SAVE_AVANDER](state, imgPath) {
		state.imgPath = imgPath;
	},
}